﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace guest_management_in_a_hotel
{

    public partial class FrmTimKiemPhong : Form
    {
        SqlConnection conn;
        SqlCommand cmd;
        SqlDataAdapter da;
        DataSet ds;
        public static string sophong;
        public FrmTimKiemPhong()
        {
            InitializeComponent();
        }

        private void btntksophong_Click(object sender, EventArgs e)
        {
            Int32 sophong = Int32.Parse(tbTKsophong.Text);
            try
            {
                
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select Room_Number[Số Phòng],Room_Description[Ghi Chú],status[Tình Trạng],Price_Per_Day[Giá / Ngày],Room_Type[Kiểu Phòng] from TblRooms where Room_Number like '%" + sophong + "%'";
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "phong");
                dgvtimkiemphong.DataSource = ds.Tables[0];
                conn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }
        }

        private void btntkkieu_Click(object sender, EventArgs e)
        {
            if (cmbtkkieuphong.Text == "Tất cả")
            {
                try
                {
                    conn = Connect.getConnection();
                    conn.Open();
                    String strSql = "select Room_Number[Số Phòng],Room_Description[Ghi Chú],status[Tình Trạng],Price_Per_Day[Giá / Ngày],Room_Type[Kiểu Phòng] from TblRooms order by Room_Type asc";
                    cmd = new SqlCommand(strSql, conn);
                    da = new SqlDataAdapter(cmd);
                    ds = new DataSet();
                    da.Fill(ds, "phong");
                    dgvtimkiemphong.DataSource = ds.Tables[0];
                    conn.Close();

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error " + ex.Message);
                }
            }

            else
            {
                try
                {
                    conn = Connect.getConnection();
                    conn.Open();
                    String strSql = "select Room_Number[Số Phòng],Room_Description[Ghi Chú],status[Tình Trạng],Price_Per_Day[Giá / Ngày],Room_Type[Kiểu Phòng] from TblRooms where Room_Type like N'%" + cmbtkkieuphong.Text + "%'";
                    cmd = new SqlCommand(strSql, conn);
                    da = new SqlDataAdapter(cmd);
                    ds = new DataSet();
                    da.Fill(ds, "phong");
                    dgvtimkiemphong.DataSource = ds.Tables[0];
                    conn.Close();

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error " + ex.Message);
                }

            }
            
        }

        private void btntkgia_Click(object sender, EventArgs e)
        {
            if (cmbtkgia.Text == "Tất cả")
            {
                try
                {
                    conn = Connect.getConnection();
                    conn.Open();
                    String strSql = "select Room_Number[Số Phòng],Room_Description[Ghi Chú],status[Tình Trạng],Price_Per_Day[Giá / Ngày],Room_Type[Kiểu Phòng] from TblRooms order by Room_Type asc";
                    cmd = new SqlCommand(strSql, conn);
                    da = new SqlDataAdapter(cmd);
                    ds = new DataSet();
                    da.Fill(ds, "phong");
                    dgvtimkiemphong.DataSource = ds.Tables[0];
                    conn.Close();

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error " + ex.Message);
                }
            }

            else{
                try
                {
                    conn = Connect.getConnection();
                    conn.Open();
                    String strSql = "select Room_Number[Số Phòng],Room_Description[Ghi Chú],status[Tình Trạng],Price_Per_Day[Giá / Ngày],Room_Type[Kiểu Phòng] from TblRooms where Price_Per_Day like '%"+cmbtkgia.Text+"%'";
                    cmd = new SqlCommand(strSql, conn);
                    da = new SqlDataAdapter(cmd);
                    ds = new DataSet();
                    da.Fill(ds, "phong");
                    dgvtimkiemphong.DataSource = ds.Tables[0];
                    conn.Close();

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error " + ex.Message);
                }
            }
            
            
        }

        private void btnquaylai_Click(object sender, EventArgs e)
        {
            FrmMain frmMain = new FrmMain();
            frmMain.Show();
            this.Hide();
        }

        private void btnXemthongtin_Click(object sender, EventArgs e)
        {
            sophong= dgvtimkiemphong.CurrentRow.Cells[0].Value.ToString();
           
            //    string quoctich= dgvQLKhach.CurrentRow.Cells[5].Value.ToString();
            // MessageBox.Show(CMND);
            FrmThongTinTK frmThongtintk = new FrmThongTinTK();
            frmThongtintk.Show();
            this.Hide();
        }

        private void btntkcmnd_Click(object sender, EventArgs e)
        {
            Int32 tkcmnd = Int32.Parse(tbtkcmnd.Text);
            try
            {

                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select TblRooms.Room_Number[Số Phòng],TblRooms.Room_Description[Ghi Chú],TblRooms.status[Tình Trạng],TblRooms.Price_Per_Day[Giá / Ngày],TblRooms.Room_Type[Kiểu Phòng],TblGuests.Guest_Name[Khách hàng đang thuê],TblReserve.Guest_Passport_No[Số CMND của khách] from TblRooms,TblReserve,TblGuests where TblReserve.Guest_Passport_No like'%" + tkcmnd + "%' and TblReserve.Room_Number=TblRooms.Room_Number and TblReserve.Guest_Passport_No=TblGuests.Guest_Passport_No";
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "phong");
                dgvtimkiemphong.DataSource = ds.Tables[0];
                conn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }
        }

    }
}
